import 'package:flutter_admin/utils/utils.dart';
import 'package:quiver/strings.dart';

class StockMoveLine {

  String? id;
  String? pickingId;
  String? pickingName;
  String? moveId;
  String? moveName;
  String? companyId;
  String? companyName;
  String? productId;
  String? productCode;
  String? productName;
  String? productDesc;
  String? productUomId;
  String? productUomName;
  String? productQty;
  String? productUomQty;
  num? qtyDone;
  String? packageId;
  String? packageName;
  String? packageLevelId;
  String? packageLevelName;
  String? lotId;
  String? lotName;
  String? resultPackageId;
  String? resultPackageName;
  String? date;
  String? ownerId;
  String? ownerName;
  String? locationId;
  String? locationName;
  String? locationDestId;
  String? locationDestName;
  String? state;
  String? reference;
  String? descriptionPicking;
  String? createUid;
  String? createName;
  String? createDate;
  String? createDateStart;
  String? createDateEnd;
  String? writeUid;
  String? writeDate;
  String? workorderId;
  String? workorderName;
  String? productionId;
  String? productionNo;
  String? jobType;
  String? jobTypeName;
  String? jobJson;
  String? inCheck;
  String? outCheck;
  String? remark;
  String? shelves;
  String? shelvesName;
  String? serialNumber;
  String? outSerialNumber;
  String? planQty;

  StockMoveLine({
    this.id,
    this.pickingId,
    this.pickingName,
    this.moveId,
    this.moveName,
    this.companyId,
    this.companyName,
    this.productId,
    this.productCode,
    this.productName,
    this.productDesc,
    this.productUomId,
    this.productUomName,
    this.productQty,
    this.productUomQty,
    this.qtyDone,
    this.packageId,
    this.packageName,
    this.packageLevelId,
    this.packageLevelName,
    this.lotId,
    this.lotName,
    this.resultPackageId,
    this.resultPackageName,
    this.date,
    this.ownerId,
    this.ownerName,
    this.locationId,
    this.locationName,
    this.locationDestId,
    this.locationDestName,
    this.state,
    this.reference,
    this.descriptionPicking,
    this.createUid,
    this.createName,
    this.createDate,
    this.createDateStart,
    this.createDateEnd,
    this.writeUid,
    this.writeDate,
    this.workorderId,
    this.workorderName,
    this.productionId,
    this.productionNo,
    this.jobType,
    this.jobTypeName,
    this.jobJson,
    this.inCheck,
    this.outCheck,
    this.remark,
    this.shelves, // 库位
    this.shelvesName, // 库位
    this.serialNumber,
    this.outSerialNumber,
    this.planQty,
  });

  StockMoveLine copyWith({
    String? id,
    String? pickingId,
    String? moveId,
    String? companyId,
    String? productId,
    String? productUomId,
    String? productQty,
    String? productUomQty,
    num? qtyDone,
    String? packageId,
    String? packageLevelId,
    String? lotId,
    String? lotName,
    String? resultPackageId,
    String? date,
    String? ownerId,
    String? locationId,
    String? locationDestId,
    String? state,
    String? reference,
    String? descriptionPicking,
    String? createUid,
    String? createName,
    String? createDate,
    String? writeUid,
    String? writeDate,
    String? workorderId,
    String? productionId,
    String? jobType,
    String? jobJson,
    String? inCheck,
    String? outCheck,
  }) {
    return new StockMoveLine(
      id: id ?? this.id,
      pickingId: pickingId ?? this.pickingId,
      moveId: moveId ?? this.moveId,
      companyId: companyId ?? this.companyId,
      productId: productId ?? this.productId,
      productUomId: productUomId ?? this.productUomId,
      productQty: productQty ?? this.productQty,
      productUomQty: productUomQty ?? this.productUomQty,
      qtyDone: qtyDone ?? this.qtyDone,
      packageId: packageId ?? this.packageId,
      packageLevelId: packageLevelId ?? this.packageLevelId,
      lotId: lotId ?? this.lotId,
      lotName: lotName ?? this.lotName,
      resultPackageId: resultPackageId ?? this.resultPackageId,
      date: date ?? this.date,
      ownerId: ownerId ?? this.ownerId,
      locationId: locationId ?? this.locationId,
      locationDestId: locationDestId ?? this.locationDestId,
      state: state ?? this.state,
      reference: reference ?? this.reference,
      descriptionPicking: descriptionPicking ?? this.descriptionPicking,
      createUid: createUid ?? this.createUid,
      createDate: createDate ?? this.createDate,
      writeUid: writeUid ?? this.writeUid,
      writeDate: writeDate ?? this.writeDate,
      workorderId: workorderId ?? this.workorderId,
      productionId: productionId ?? this.productionId,
      jobType: jobType ?? this.jobType,
      jobJson: jobJson ?? this.jobJson,
      inCheck: inCheck ?? this.inCheck,
      outCheck: outCheck ?? this.outCheck,
    );
  }

  @override
  String toString() {
    return '''StockMoveLine{
      id: id,
      pickingId: pickingId,
      moveId: moveId,
      companyId: companyId,
      productId: productId,
      productUomId: productUomId,
      productQty: productQty,
      productUomQty: productUomQty,
      qtyDone: qtyDone,
      packageId: packageId,
      packageLevelId: packageLevelId,
      lotId: lotId,
      lotName: lotName,
      resultPackageId: resultPackageId,
      date: date,
      ownerId: ownerId,
      locationId: locationId,
      locationDestId: locationDestId,
      state: state,
      reference: reference,
      descriptionPicking: descriptionPicking,
      createUid: createUid,
      createDate: createDate,
      writeUid: writeUid,
      writeDate: writeDate,
      workorderId: workorderId,
      productionId: productionId,
      jobType: jobType,
      jobJson: jobJson,
      inCheck: inCheck,
      outCheck: outCheck,
    }''';
  }

  @override
  bool operator ==(Object other) => identical(this, other) || (
      other is StockMoveLine &&
          runtimeType == other.runtimeType
          && id== other.id
          && pickingId== other.pickingId
          && moveId== other.moveId
          && companyId== other.companyId
          && productId== other.productId
          && productUomId== other.productUomId
          && productQty== other.productQty
          && productUomQty== other.productUomQty
          && qtyDone== other.qtyDone
          && packageId== other.packageId
          && packageLevelId== other.packageLevelId
          && lotId== other.lotId
          && lotName== other.lotName
          && resultPackageId== other.resultPackageId
          && date== other.date
          && ownerId== other.ownerId
          && locationId== other.locationId
          && locationDestId== other.locationDestId
          && state== other.state
          && reference== other.reference
          && descriptionPicking== other.descriptionPicking
          && createUid== other.createUid
          && createDate== other.createDate
          && writeUid== other.writeUid
          && writeDate== other.writeDate
          && workorderId== other.workorderId
          && productionId== other.productionId
          && jobType== other.jobType
          && jobJson== other.jobJson
          && inCheck== other.inCheck
          && outCheck== other.outCheck
   );


  factory StockMoveLine.fromMap(Map<String, dynamic> map) {
    return new StockMoveLine(
      id: map['id']!=false?map['id'].toString() as String?:"",
      pickingId: map['picking_id']!=false?map['picking_id'][0].toString() as String?:"",
      pickingName: map['picking_id']!=false?map['picking_id'][1].toString() as String?:"",
      moveId: map['move_id']!=false?map['move_id'][0].toString() as String?:"",
      moveName: map['move_id']!=false?map['move_id'][1].toString() as String?:"",
      companyId: map['company_id']!=false?map['company_id'][0].toString() as String?:"",
      companyName: map['company_id']!=false?map['company_id'][1].toString() as String?:"",
      productId: map['product_id']!=false?map['product_id'][0].toString() as String?:"",
      productCode: map['product_default_code']!=false?map['product_default_code'].toString() as String?:"",
      productName: map['product_name']!=false?map['product_name'].toString() as String?:"",
      productDesc: map['product_desc']!=false?map['product_desc'].toString() as String?:"",
      productUomId: map['product_uom_id']!=false?map['product_uom_id'][0].toString() as String?:"",
      productUomName: map['product_uom_id']!=false?map['product_uom_id'][1].toString() as String?:"",
      productQty: map['product_qty']!=false?map['product_qty'].toString() as String?:"",
      productUomQty: map['product_uom_qty']!=false?map['product_uom_qty'].toString() as String?:"",
      qtyDone: map['qty_done']!=false?map['qty_done']:0,
      packageId: map['package_id']!=false?map['package_id'][0].toString() as String?:"",
      packageName: map['package_id']!=false?map['package_id'][1].toString() as String?:"",
      packageLevelId: map['package_level_id']!=false?map['package_level_id'][0].toString() as String?:"",
      packageLevelName: map['package_level_id']!=false?map['package_level_id'][1].toString() as String?:"",
      lotId: map['lot_id']!=false?map['lot_id'].toString() as String?:"",
      lotName: map['lot_name']!=false?map['lot_name'].toString() as String?:"",
      resultPackageId: map['result_package_id']!=false?map['result_package_id'][0].toString() as String?:"",
      resultPackageName: map['result_package_id']!=false?map['result_package_id'][1].toString() as String?:"",
      date: map['date']!=false?map['date'].toString() as String?:"",
      ownerId: map['owner_id']!=false?map['owner_id'][0].toString() as String?:"",
      ownerName: map['owner_id']!=false?map['owner_id'][1].toString() as String?:"",
      locationId: map['location_name']!=false?map['location_name'][0].toString() as String?:"",
      locationName: map['location_name']!=false?map['location_name'][1].toString() as String?:"",
      locationDestId: map['location_dest_name']!=false?map['location_dest_name'][0].toString() as String?:"",
      locationDestName: map['location_dest_name']!=false?map['location_dest_name'][1].toString() as String?:"",
      state: map['state']!=false?map['state'].toString() as String?:"",
      reference: map['reference']!=false?map['reference'].toString() as String?:"",
      descriptionPicking: map['description_picking']!=false?map['description_picking'].toString() as String?:"",
      createUid: map['create_uid']!=false?map['create_uid'][0].toString() as String?:"",
      createName: map['create_uid']!=false?map['create_uid'][1].toString() as String?:"",
      createDate: map['create_date']!=false?map['create_date'].toString() as String?:"",
      writeUid: map['write_uid']!=false?map['write_uid'].toString() as String?:"",
      writeDate: map['write_date']!=false?map['write_date'].toString() as String?:"",
      workorderId: map['workorder_id']!=false?map['workorder_id'][0].toString() as String?:"",
      workorderName: map['workorder_id']!=false?map['workorder_id'][1].toString() as String?:"",
      productionId: map['production_id']!=false?map['production_id'][0].toString() as String?:"",
      productionNo: map['production_no']!=false?map['production_no'].toString() as String?:"",
      jobType: map['job_type']!=false?map['job_type'][0].toString() as String?:"",
      jobTypeName: map['job_type']!=false?map['job_type'][1].toString() as String?:"",
      jobJson: map['job_json']!=false?map['job_json'].toString() as String?:"",
      inCheck: map['in_check']!=false?map['in_check'].toString() as String?:"",
      outCheck: map['out_check']!=false?map['out_check'].toString() as String?:"",
      remark: map['remark']!=false?map['remark'].toString() as String?:"",
      serialNumber: map['serial_number']!=false?map['serial_number'].toString() as String?:"",
      outSerialNumber: map['out_serial_number']!=false?map['out_serial_number'].toString() as String?:"",
      planQty: map['plan_qty']!=false?map['plan_qty'].toString() as String?:"0",
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'pickingId': this.pickingId,
      'moveId': this.moveId,
      'companyId': this.companyId,
      'productId': this.productId,
      'productUomId': this.productUomId,
      'productQty': this.productQty,
      'productUomQty': this.productUomQty,
      'qtyDone': this.qtyDone,
      'packageId': this.packageId,
      'packageLevelId': this.packageLevelId,
      'lotId': this.lotId,
      'lotName': this.lotName,
      'resultPackageId': this.resultPackageId,
      'date': this.date,
      'ownerId': this.ownerId,
      'locationId': this.locationId,
      'locationDestId': this.locationDestId,
      'state': this.state,
      'reference': this.reference,
      'descriptionPicking': this.descriptionPicking,
      'createUid': this.createUid,
      'createDate': this.createDate,
      'writeUid': this.writeUid,
      'writeDate': this.writeDate,
      'workorderId': this.workorderId,
      'productionId': this.productionId,
      'jobType': this.jobType,
      'jobJson': this.jobJson,
      'inCheck': this.inCheck,
      'outCheck': this.outCheck,
    } as Map<String, dynamic>;
  }

  List toDomainList({String? scene}) {
    List list = [
      if (this.createDateStart != null && this.createDateStart != '')
        [
          'create_date',
          '>=',
          Utils.timeUTC(this.createDateStart! + " 00:00:00", isToBeijing: false)
        ],
      if (this.createDateEnd != null && this.createDateEnd != '')
        [
          'create_date',
          '<=',
          Utils.timeUTC(this.createDateEnd! + " 23:59:59", isToBeijing: false)
        ],
      if (this.locationId != null && this.locationId != '')
        ['location_name', '=', int.parse(this.locationId!)],
      if (this.productCode != null && this.productCode != '')
        ['product_id.default_code', 'like', '%${this.productCode}%'],
      if (this.productName != null && this.productName != '')
        ['product_id.name', 'like', '%${this.productName}%'],
      if (this.serialNumber != null && this.serialNumber != '')
        ['serial_number', '=', this.serialNumber],
    ];
    // ignore: unnecessary_cast
    return list;
  }

  List toInSearchDomainList() {
    List list = [
      ['job_type.scene','=','入库'],
      ['in_check','=','1'],
      if (this.createDateStart != null && this.createDateStart != '')
        [
          'create_date',
          '>=',
          Utils.timeUTC(this.createDateStart! + " 00:00:00", isToBeijing: false)
        ],
      if (this.createDateEnd != null && this.createDateEnd != '')
        [
          'create_date',
          '<=',
          Utils.timeUTC(this.createDateEnd! + " 23:59:59", isToBeijing: false)
        ],
      if (this.locationId != null && this.locationId != '')
        ['location_name', '=', int.parse(this.locationId!)],
      if (this.productCode != null && this.productCode != '')
        ['product_id.default_code', 'like', '%${this.productCode}%'],
      if (this.productName != null && this.productName != '')
        ['product_id.name', 'like', '%${this.productName}%'],
    ];
    // ignore: unnecessary_cast
    return list;
  }

  List toOutSearchDomainList() {
    List list = [
      ['job_type.scene','=','出库'],
      if (this.createDateStart != null && this.createDateStart != '')
        [
          'create_date',
          '>=',
          Utils.timeUTC(this.createDateStart! + " 00:00:00", isToBeijing: false)
        ],
      if (this.createDateEnd != null && this.createDateEnd != '')
        [
          'create_date',
          '<=',
          Utils.timeUTC(this.createDateEnd! + " 23:59:59", isToBeijing: false)
        ],
      if (this.locationId != null && this.locationId != '')
        ['location_name', '=', int.parse(this.locationId!)],
      if (this.productCode != null && this.productCode != '')
        ['product_id.default_code', 'like', '%${this.productCode}%'],
      if (this.productName != null && this.productName != '')
        ['product_id.name', 'like', '%${this.productName}%'],
    ];
    // ignore: unnecessary_cast
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': isBlank(this.id)?null:int.parse(this.id!),
      'product_id': int.parse(this.productId!),
      'product_uom_id': int.parse(this.productUomId!),
      'company_id': 3,
      'qty_done': this.qtyDone,
      'lot_name': this.lotName,
      'job_type': this.jobType,
      'job_json': this.jobJson,
      'production_no': this.productionNo,
      'location_name': int.parse(this.locationId!),
      'shelves': isBlank(shelves)?null:int.parse(this.shelves!),
      'remark': this.remark,
      'location_id':106,//必填，在我们的数据模式中无意义，但是在odoo中不填会报错，此处定义一个死的ID
      'location_dest_id':95,//必填，在我们的数据模式中无意义，但是在odoo中不填会报错，此处定义一个死的ID
    } as Map<String, dynamic>;
  }

  // Map<String, dynamic> toInOdooMap() {
  //   // ignore: unnecessary_cast
  //   return {
  //     'id': this.id,
  //     'product_id': int.parse(this.productId!),
  //     'product_uom_id': int.parse(this.productUomId!),
  //     // 'product_qty': this.productQty,
  //     // 'product_uom_qty': this.productUomQty,
  //     'company_id': 3,
  //     'qty_done': this.qtyDone,
  //     'lot_name': this.lotName,
  //     'job_type': this.jobType,
  //     'job_json': this.jobJson,
  //     'production_no': this.productionNo,
  //     'location_name': int.parse(this.locationId!),
  //     'shelves': isBlank(shelves)?null:int.parse(this.shelves!),
  //     'remark': this.remark,
  //     'location_id':106,//必填，在我们的数据模式中无意义，但是在odoo中不填会报错，此处定义一个死的ID
  //     'location_dest_id':95,//必填，在我们的数据模式中无意义，但是在odoo中不填会报错，此处定义一个死的ID
  //   } as Map<String, dynamic>;
  // }
  //
  Map<String, dynamic> toOutOdooMap(String? quantId) {
    // ignore: unnecessary_cast
    return {
      'id': isBlank(this.id)?null:int.parse(this.id!),
      'product_id': int.parse(this.productId!),
      'product_uom_id': int.parse(this.productUomId!),
      // 'product_qty': this.productQty,
      // 'product_uom_qty': this.productUomQty,
      'company_id': 3,
      'qty_done': this.qtyDone,
      'plan_qty': this.qtyDone,
      'lot_name': this.lotName,
      'job_type': this.jobType,
      'job_json': this.jobJson,
      'production_no': this.productionNo,
      'location_name': int.parse(this.locationId!),
      // 'location_dest_name': int.parse(this.locationDestId!),
      'shelves': isBlank(shelves)?null:int.parse(this.shelves!),
      'remark': this.remark,
      'quant_id': int.parse(quantId!),
      'location_id':106,//必填，在我们的数据模式中无意义，但是在odoo中不填会报错，此处定义一个死的ID
      'location_dest_id':95,//必填，在我们的数据模式中无意义，但是在odoo中不填会报错，此处定义一个死的ID
    } as Map<String, dynamic>;
  }

//</editor-fold>

}